//
//  StoreCategoryCollectionCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/6.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreCategoryCollectionCell.h"
#import "HomeADItemEventModel.h"
#import "ProClassificationModel.h"
@interface StoreCategoryCollectionCell ()
@property(nonatomic, strong) UIImageView *mainImageView;
@property(nonatomic, strong) UILabel *mainTitle;
@end
@implementation StoreCategoryCollectionCell
- (void)makeUI {
    [super makeUI];
    [self.contentView addSubview:self.mainImageView];
    [self.contentView addSubview:self.mainTitle];
    
    [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(28, 28));
        make.top.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
    }];
    [self.mainTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mainImageView.mas_bottom).mas_equalTo(7.5);
        make.centerX.mas_equalTo(0);
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}
- (void)setData:(HomeADItemEventModel *)data {
    _data = data;
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:data.url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.mainTitle.text = data.iconName;
}
- (void)setData2:(ProClassificationModel *)data {
    _data2 = data;
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:data.icon]  placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.mainTitle.text = data.parentName;
}
#pragma mark - lazy
- (UIImageView *)mainImageView {
    if (!_mainImageView) {
        UIImageView *iv = [[UIImageView alloc]init];
        iv.contentMode = UIViewContentModeScaleAspectFill;
        iv.clipsToBounds = YES;
        _mainImageView = iv;
    }
    return _mainImageView;
}
- (UILabel *)mainTitle {
    if (!_mainTitle) {
        UILabel *lab = [[UILabel alloc]init];
        lab.font = kFontRegular12;
        lab.textColor = rgba(47, 47, 52, 1);
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        _mainTitle = lab;
    }
    return _mainTitle;
}
@end
